home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / capstest.lha / capstest.c < prev    next >
C/C++ Source or Header  |  1994-12-02  |  1KB  |  52 lines

  1. ;/* execute me to compile
  2.  
  3. dcc -ECONSOLE: -proto -pr -mS -mr -l0 -ocapstest capstest.c
  4. quit
  5.  
  6.  *
  7.  * $VER: CapsTest.c 1.0 (2.12.94)
  8.  *
  9.  * Public Domain by Lauri Aalto <lauri.aalto@fipnet.fi>
  10.  *
  11.  * Reads keyboard matrix and outputs 0/1 depending on caps lock key status.
  12.  */
  13.  
  14. #include <exec/exec.h>
  15. #include <dos/dos.h>
  16. #include <devices/keyboard.h>
  17. #include <pragmas/exec_pragmas.h>
  18. #include <pragmas/dos_pragmas.h>
  19.  
  20. __geta4 void CapsTest() {
  21.     struct Library *SysBase;
  22.     struct Library *DOSBase;
  23.     struct IOStdReq *io;
  24.     struct MsgPort *port;
  25.     char *matrix;
  26.  
  27.     SysBase = *((struct Library **)4);
  28.     if (DOSBase = OpenLibrary("dos.library", 36)) {
  29.         if (port = CreateMsgPort()) {
  30.             if (io = CreateIORequest(port, sizeof(struct IOStdReq))) {
  31.                 if (!(OpenDevice("keyboard.device", 0, (struct IORequest *)io, 0))) {
  32.                     if (matrix = AllocVec(20, MEMF_PUBLIC | MEMF_CLEAR)) {
  33.                         io->io_Command = KBD_READMATRIX;
  34.                         io->io_Data = matrix;
  35.                         io->io_Length = 20;
  36.                         DoIO((struct IORequest *)io);
  37.                         if (matrix[12] & (1 << 2)) Write(Output(), "1\n", 2);
  38.                         else Write(Output(), "0\n", 2);
  39.                         FreeVec(matrix);
  40.                     }
  41.                     CloseDevice((struct IORequest *)io);
  42.                 }
  43.                 DeleteIORequest((struct IORequest *)io);
  44.             }
  45.             DeleteMsgPort(port);
  46.         }
  47.         CloseLibrary(DOSBase);
  48.     }
  49. }
  50.  
  51. static const char version[] = "\0$VER: CapsTest 1.0 (" __COMMODORE_DATE__ ")";
  52.